import logging
from logging.handlers import RotatingFileHandler

formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')


def setRotatingRootLogger(filename, level=logging.INFO):
    handler = RotatingFileHandler(filename, encoding='UTF-8', maxBytes=1000000, backupCount=5)
    handler.setFormatter(formatter)
    logger = logging.getLogger()
    logger.setLevel(level)
    logger.addHandler(handler)


def get_rotatingfilehandler(logfile):
    handler = RotatingFileHandler(logfile, maxBytes=1000000, backupCount=5)
    handler.setFormatter(formatter)

    return handler
